package main

import (
	"os"

	"gitee.com/xuender/mysql-proxy/pb"
	"github.com/BurntSushi/toml"
	"github.com/xuender/oils/base"
)

func main() {
	const (
		port  = 3306
		limit = 1000
		web   = 8000
	)

	config := &pb.Config{
		Port:    port,
		WebPort: web,
		Conns: []*pb.Conn{{
			Id:       1,
			Name:     "测试",
			Charset:  "utf8mb4",
			Username: "hexin",
			Password: "hexin",
			Address:  "192.168.1.10:3306",
			Schema:   "test",
			Users:    []*pb.User{{User: "root", Password: "root"}},
		}},
		DefaultLimit: limit,
		Ldap: &pb.Ldap{
			// Url:      "openldap.woda.com:636",
			// User:     "cn=readonly,dc=dev,dc=woda,dc=com",
			// Password: "readonlyWoda2019",
			Sc:     "ou=users,dc=dev,dc=woda,dc=com",
			Filter: "(uid=%s)",
		},
		PassCodes: []string{"FUN.002"},
		Auth:      map[string]string{"admin": "123"},
	}

	base.Panic(config.Save("proxy.toml"))

	pass := &pb.Pass{Prefix: []string{"xxx", "fff"}, Contains: []string{"sdf", "kkk"}}

	file := base.Panic1(os.CreateTemp("proxy", "test"))
	defer file.Close()
	defer os.Remove(file.Name())

	encoder := toml.NewEncoder(file)

	base.Panic(encoder.Encode(pass))
}
